package logic

import (
	"context"

	"cloud-disk/core/internal/svc"
	"cloud-disk/core/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserFolderCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserFolderCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFolderCreateLogic {
	return &UserFolderCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserFolderCreateLogic) UserFolderCreate(req *types.UserFolderCreateRequest, userIdentity string) (resp *types.UserFolderCreateResponse, err error) {
	resp = new(types.UserFolderCreateResponse)
	ur, err := l.svcCtx.UserRepostioryModel.CreateFolder(req.Name, userIdentity, req.ParentId)
	if err != nil {
		resp.Message = "创建文件夹失败 " + err.Error()
		resp.Code = 100
		return resp, nil
	}

	resp.Message = "创建成功"
	resp.Code = 200
	resp.Identity = ur.Identity
	return resp, nil
}
